package com.ymttest.database.mapping;

import com.ymttest.database.model.YmtCssession;
import com.ymttest.database.model.YmtCssessionHistory;
import com.ymttest.database.model.YmtOnlinecs;
import com.ymttest.database.model.YmtQueuesession;
import com.ymttest.database.model.YmtRiskymessage;
import com.ymttest.database.model.YmtRiskyuser;

import java.util.Date;
import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.InsertProvider;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

public interface YmtSellerCSIMMapper {
	//在线状态
    /**
     * This method was generated by MyBatis Generator.
     * This method corresponds to the database table ymt_onlinecs
     *
     * @mbggenerated Tue Oct 09 09:50:27 CST 2018
     */
    @Insert({
        "insert into ymt_onlinecs (Id, MasterCSId, ",
        "CSId, CSName, Status, ",
        "LoginStatus, CurrentSessions, ",
        "LastActiveTime, SocketIoToken)",
        "values (#{id,jdbcType=VARCHAR}, #{masterCSId,jdbcType=INTEGER}, ",
        "#{CSId,jdbcType=INTEGER}, #{CSName,jdbcType=VARCHAR}, #{status,jdbcType=INTEGER}, ",
        "#{loginStatus,jdbcType=INTEGER}, #{currentSessions,jdbcType=INTEGER}, ",
        "#{lastActiveTime,jdbcType=TIMESTAMP}, #{socketIoToken,jdbcType=VARCHAR})"
    })
    int insertYmtOnlinecs(YmtOnlinecs record);
    @Select("<script>" + "select * from ymt_onlinecs" + "<where>"
			+ "<if test='mcsid !=null '>" + "MasterCSId=#{mcsid}	" + "</if>"
			+ "<if test='csid !=null '>"	+ " and CSId=#{csid}" + "</if>"
			+ "</where>" + "</script>")
    List<YmtOnlinecs> selectYmtOnlinecs(Map m);
    @Delete("delete  from ymt_onlinecs where CSId=#{csid}")
    int deleteYmtOnlinecsByCsid(Integer csid);
    
    @Update("update  ymt_onlinecs set LoginStatus =#{ls} where CSId=#{csid}")
    int updateYmtOnlinecsSetLoginStatus(Map m);
    //风控用户
    @Insert({
        "insert into ymt_riskyuser (UserId, Disabled, ",
        "RegisterTime, CreateTime, ",
        "UpdateTime)",
        "values (#{userId,jdbcType=INTEGER}, #{disabled,jdbcType=BIT}, ",
        "#{registerTime,jdbcType=TIMESTAMP}, #{createTime,jdbcType=TIMESTAMP}, ",
        "#{updateTime,jdbcType=TIMESTAMP})"
    })
    int insertYmtRiskyuser(YmtRiskyuser record);
    @Select("select * from ymt_riskyuser where userid=#{uid}")
    List<YmtRiskyuser> selectYmtRiskyuserByUid(@Param("uid")Integer uid);
    @Update("update  ymt_riskyuser set Disabled=#{disable} where userid=#{uid}")
    int updateYmtRiskyuserByUid(@Param("uid")Integer uid,@Param("disable")Boolean disable);
    
//    @Select(" select * from ymt_riskymessage where fromuserid=4085 and touserid=3383 order by createddate desc")
    @Select("<script>" + "select * from ymt_riskymessage" + "<where>"
			+ "<if test='from !=null '>" + "fromuserid=#{from}	" + "</if>"
			+ "<if test='to !=null '>"	+ " and touserid=#{to}" + "</if>"
			+ "</where>" + " order by createddate desc </script>")
    List<YmtRiskymessage> selectYmtRiskymessage(@Param("from")Integer fromuid,@Param("to")Integer touid);
    
    //会话session
    @Select("<script>" + "select * from ymt_queuesession" + "<where>"
			+ "<if test='mcsid !=null '>" + "MasterCsid=#{mcsid}	" + "</if>"
			+ "<if test='userid !=null '>"	+ " and userid=#{userid}" + "</if>"
			+ "</where>" + " order by lastmessagetime desc </script>")
    List<YmtQueuesession> selectYmtQueuesession(@Param("mcsid")Integer mcsid,@Param("userid")Integer userid);

    @Select("<script>" + "select * from Ymt_Cssession" + "<where>"
			+ "<if test='mcsid !=null '>" + "MasterCsid=#{mcsid}	" + "</if>"
			+ "<if test='userid !=null '>"	+ " and userid=#{userid}" + "</if>"
			+ "</where>" + " order by lastmessagetime desc </script>")
    List<YmtCssession> selectYmtCssession(@Param("mcsid")Integer mcsid,@Param("userid")Integer userid);
    
    @Select("select i.id as id,ic.CategoryId as CategoryId,ic.CSId as CSId,ic.Sort as icSort,ic.Title as icTitle,i.Sort as cSort,i.Title as cTitle from ymt_individualdiscoursecatetory ic left join ymt_individualdiscourse i on ic.CategoryId=i.CategoryId where ic.csid=#{csid}")
    List<Map> selectIndividualdiscourseByCsid(@Param("csid")Integer csid);
    
    @Update("update  ymt_cssession set LastMessageTime=#{LastMessageTime} where id=#{id}")
    int updateYmtCssessionLastMessageTime(@Param("id")String id,@Param("LastMessageTime")Date LastMessageTime);
    
    @Update("update  ymt_onlinecs set LastActiveTime=#{LastActiveTime} where csid=#{csid}")
    int updateYmtOnlinecsLastActiveTime(@Param("csid")String csid,@Param("LastActiveTime")Date LastMessageTime);
    @Select("<script>" + "select * from ymt_cssession_history" + "<where>"
			+ "<if test='mcsid !=null '>" + "MasterCsid=#{mcsid}	" + "</if>"
			+ "<if test='userid !=null '>"	+ " and userid=#{userid}" + "</if>"
			+ "</where>" + " order by lastmessagetime desc </script>")
    List<YmtCssessionHistory> selectYmtCssessionHistory(@Param("mcsid")Integer mcsid,@Param("userid")Integer userid);
}